# Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

IF(STATIC_MSVCRT) 
  SET(STATIC_MSVCRT "ON")
ELSE()
  SET(STATIC_MSVCRT "OFF")
ENDIF()
SET(BUNDLE_RUNTIME_LIBRARIES "@BUNDLE_RUNTIME_LIBRARIES@")
SET(CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@")
SET(CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
SET(CANDLE_EXECUTABLE "@CANDLE_EXECUTABLE@")
SET(LIGHT_EXECUTABLE "@LIGHT_EXECUTABLE@")
SET(CMAKE_COMMAND "@CMAKE_COMMAND@")
SET(CMAKE_CFG_INTDIR "@CMAKE_CFG_INTDIR@")
SET(VERSION "@VERSION@")
SET(MAJOR_VERSION "@CONCPP_VERSION_MAJOR@")
SET(MINOR_VERSION "@CONCPP_VERSION_MINOR@")
SET(PATCH_VERSION "@CONCPP_VERSION_MICRO@")
SET(CMAKE_SIZEOF_VOID_P @CMAKE_SIZEOF_VOID_P@)
SET(MANUFACTURER "Oracle Corporation")
# SET(WIXCA_LOCATION "@WIXCA_LOCATION@")
SET(LICENSE_RTF "@LICENSE_RTF@")
SET(CPACK_WIX_CONFIG "@CPACK_WIX_CONFIG@")
SET(CPACK_WIX_INCLUDE "@CPACK_WIX_INCLUDE@")
SET(CPACK_MSI_SETUP "@CPACK_MSI_SETUP@")
SET(PRODUCT_NAME "MySQL Connector C++")
SET(PRODUCT_DESCRIPTION "MySQL Connector C++")

SET(UPGRADE_CODE_32_BIT "72D894D6-D313-41F0-A615-A3CF1F1DF749")
SET(UPGRADE_CODE_64_BIT "97D95CF0-B505-4D50-B78B-3515AAB991F1")
SET(UPGRADE_CODE_OLD "FE990D78-8BB1-4880-930A-0430E707F3CA")

IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
  SET(Platform x64)
  SET(PlatformProgramFilesFolder ProgramFiles64Folder)
  SET(UPGRADE_CODE "${UPGRADE_CODE_64_BIT}")
  SET(Is64bit "yes")
ELSE()
  SET(Platform x86)
  SET(PlatformProgramFilesFolder ProgramFilesFolder)
  SET(UPGRADE_CODE "${UPGRADE_CODE_32_BIT}")
  SET(Is64bit "no")
ENDIF()

INCLUDE(${CPACK_MSI_SETUP})

CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/connector-cpp.wxs.in 
 ${CMAKE_CURRENT_BINARY_DIR}/connector-cpp.wxs)

SET(EXTRA_CANDLE_ARGS)
IF("$ENV{EXTRA_CANDLE_ARGS}")
	SET(EXTRA_CANDLE_ARGS "$ENV{EXTRA_CANDLE_ARGS}")
ENDIF()

SET(EXTRA_LIGHT_ARGS)
IF("$ENV{EXTRA_LIGHT_ARGS}")
	SET(EXTRA_LIGHT_ARGS "$ENV{EXTRA_LIGHT_ARGS}")
ENDIF()

FILE(REMOVE connector-cpp.wixobj)
EXECUTE_PROCESS(
 COMMAND ${CANDLE_EXECUTABLE} -ext WixUtilExtension  connector-cpp.wxs ${EXTRA_CANDLE_ARGS}
 RESULT_VARIABLE CANDLE_RESULT
)

IF(CANDLE_RESULT)
  MESSAGE(FATAL_ERROR "ERROR: can't run candle")
ENDIF()

EXECUTE_PROCESS(
 COMMAND ${LIGHT_EXECUTABLE} -ext WixUIExtension -ext WixUtilExtension
  connector-cpp.wixobj  -out  ${CMAKE_BINARY_DIR}/${CPACK_PACKAGE_FILE_NAME}.msi
  ${EXTRA_LIGHT_ARGS}
 RESULT_VARIABLE LIGHT_RESULT
)

IF(LIGHT_RESULT)
  MESSAGE(FATAL_ERROR "ERROR: can't run light")
ENDIF()
